/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { FP, GP } from './symbols';

export class TmpBase {
  type: string;
  isReg: boolean = false;

  constructor(type: string) {
    this.type = type;
    this.isReg = false;
  }
  get isGP(): boolean {
    return this.type === GP;
  }

  get isFP(): boolean {
    return this.type === FP;
  }

  get isGPR(): boolean {
    return this.isReg && this.isGP;
  }

  get isFPR(): boolean {
    return this.isReg && this.isFP;
  }

  reg(): TmpBase {
    if (!this.isReg) {
      throw new Error('Called .reg on non-Reg');
    }
    return this;
  }

  gpr(): TmpBase {
    if (!this.isGPR) {
      throw new Error('Called .gpr on non-GPR');
    }
    return this;
  }

  fpr(): TmpBase {
    if (!this.isFPR) {
      throw new Error('Called .fpr on non-FPR');
    }
    return this;
  }
}
